<template>
	<view class="content">
		<view style="height: 275rpx;background-color: #1262DB;">
			<view style="height: 40rpx;"></view>
			<view class="wid90 mar bacFFF borRad10">
				<uni-datetime-picker v-model="datetimerange" type="daterange" rangeSeparator="至" @change="changeTime" />
			</view>
			<view class="textCen coFFF mar-top20 foSi30">
				<view>总收益</view>
				<view class="mar-top10">¥{{parseFloat(total_revenue).toFixed(2)}}</view>
			</view>
		</view>
		<view class="" style="display: flex;justify-content: space-around;margin-top: 20rpx;margin-bottom: 20rpx;">
			<view class="" style="display: flex;flex-direction: column;align-items: center;">
				<view class="yuan">
					检测收益
				</view>
				<view class="" style="margin-top: 15rpx;color:#4c4c4c">
					￥{{jc}}
				</view>
			</view>
			<view class="" style="display: flex;flex-direction: column;align-items: center;">
				<view class="yuan">
					试剂返还
				</view>
				<view class="" style="margin-top: 15rpx;color:#4c4c4c">
					￥{{sj}}
				</view>
			</view>
		</view>
		<!-- disJuB -->
		<view class="wid90 mar mar-top30 dis disAl " style="height: 220rpx;justify-content: space-around;" v-if="system_type == 1">
			<view class="textCen" style="">
				<view class="dis disAl disJuC wh foSi30 borRad40" @click="chengType(1)" 
				:style="type == 1?'background-color: #1262DB;color: #fff;':''">检测收益</view>
				<view class="mar-top30 foSi40" :style="type == 1?'color: #1262DB;':'color: #AEACAC;'">¥{{parseFloat(jiance_revenue).toFixed(2)}}</view>
			</view>
			<!-- <view class="textCen" style="">
				<view class="dis disAl disJuC wh foSi30 borRad40" @click="chengType(2)" 
				:style="type == 2?'background-color: #1262DB;color: #fff;':''">仪器押金</view>
				<view class="mar-top30 foSi40" :style="type == 2?'color: #1262DB;':'color: #AEACAC;'">¥0.00</view>
			</view> -->
			<view class="textCen" style="">
				<view class="dis disAl disJuC wh foSi30 borRad40" @click="chengType(3)" 
				:style="type == 3?'background-color: #1262DB;color: #fff;':''">试剂返还</view>
				<view class="mar-top30 foSi40" :style="type == 3?'color: #1262DB;':'color: #AEACAC;'">¥{{parseFloat(yajin_revenue).toFixed(2)}}</view>
			</view>
		</view>
		<view class="xhx"></view>
		<scroll-view style="height: calc(100vh - 526rpx);" scroll-y="true" class="scroll-Y" @scrolltolower="lower">
			<view v-if="list.length == 0" class="wh100 dis disAl disJuC">
				<image src="../../static/incomeDetail/wushiju.png" style="width: 197rpx;height: 226rpx;"></image>
			</view>
			<view v-if="list.length != 0" class="foSi30 mar-top20"
				v-for="(item,index) in list" :key="index">
				<view class="wid90 mar hei60 dis disAl disJuB">
					<view>{{item.createtime}}</view>
					<view style="color: #2088f8;">返还金额：￥{{parseFloat(item.money).toFixed(2)}}</view>
				</view>
				<view class="wid90 mar mar-top10" style="font-weight: 600;">订单编号：{{item.oid}}</view>
				<view class="wid90 mar mar-top10" style="color: #AEACAC;">{{item.notes}}</view>
				<view style="height: 20rpx;"></view>
				<view class="xhx"></view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 1,
				list: [],
				datetimerange: [],
				page: 0,
				total_revenue:'',
				jiance_revenue:'',
				yajin_revenue:'',
				jc:'',
				sj:'',
				last_page: 0,
				system_type:1
				
			}
		},
		onLoad() {
			this.system_type = uni.getStorageSync('system_type')
			console.log('啥')
			console.log(this.system_type)
			this.dangqian()
		
		},
		methods: {
			dangqian(){
				this.zhanshi = 0
				var date = new Date()
				var year = date.getFullYear()
				var month = date.getMonth() + 1
				var day = date.getDate()
				this.datetimerange = [year+'-'+month+'-'+day,year+'-'+month+'-'+day]
				this.getuserinfo()
			},
			chengType(index){
				this.type = index
				this.page = 0
				this.getuserinfo()
			},
			changeTime(e) {
				this.datetimerange = e;
				if(e.length != 0){
					this.page = 0
					this.getuserinfo()
				}
			},
			getuserinfo(){
				
				var that = this
				if(uni.getStorageSync('system_type') == 1){
					var urls = 'api/order/revenue_details'
				}else{
					var urls = 'api/order/revenue_details2'
				}
				uni.request({
				    url: that.global.url + urls,
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						begintime: this.datetimerange[0],
						endtime: this.datetimerange[1],
						page: this.page,
						type: this.type
					},
				    success(res) {
				        let result = res.data
				        if(result.code == 1){
							if(that.page == 0){
								that.list = result.data.data.data
							}else{
								that.list = that.list.concat(result.data.data.data)
							}
							that.last_page = result.data.data.last_page
							that.total_revenue = result.data.total_revenue
							that.jiance_revenue = result.data.jiance_revenue
							that.yajin_revenue = result.data.yajin_revenue
							that.jc = result.data.jc
							that.sj = result.data.sj
						}else{
				           uni.showToast({
				           	title: result.msg,
				           	icon: 'error'
				           })
				        }
				       
				    }
				})
			},
			lower: function(e) {
				if(this.last_page != this.page+1){
					this.page++
					this.getuserinfo()
				}
			},
		}
	}
</script>

<style>
	.content {}
	.uni-date-x--border {
		height: 90rpx;
	}
	.wh{
		width: 190rpx;
		height: 76rpx;
		border: 1rpx solid #AEACAC;
		color: #AEACAC;
	}
	.yuan{
		padding: 15rpx 30rpx;
		border: 1px solid #ccc;
		border-radius: 25rpx;
		font-size: 28rpx;
		
	}
</style>
